package win.zxshuo.www.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfigurer implements WebMvcConfigurer {

//    // 需要autowired或者service 需要整个类中有Configuration 注解来自动注解为Java bean
//    @Autowired
//    TokenHandlerInterceptor tokenHandlerInterceptor;

    //TODO 需要见一个Session 处理的类，来处理页面的session

    public void addInterceptors(InterceptorRegistry registry){
//        registry.addInterceptor(new SessionHandlerInterceptor()).addPathPatterns("/go/**");
//        registry.addInterceptor(tokenHandlerInterceptor)
//                .addPathPatterns("/api/auth/**")
//                .addPathPatterns("/go/add");
    }

    /**
     * 添加跨域设置，将其他所有链接的跨域都设置为OK
     * @param registry
     */
    public void addCorsMappings(CorsRegistry registry){
        registry.addMapping("/**")
                .allowedHeaders("*")
                .allowedMethods("*")
                .allowedOrigins("*");
    }
}
